#!/bin/bash

# myshell tools
# merge prev branch to current and push current branch to remote
# usage:
#   git-merge-push.sh 
#        $1: tag(section name) for git configure in passwd.cnf
#        $2: commit message
# remark:
#  if report error with not found "read-passwd" function or command,
#  pelase exec install.sh first.

function fatal()
{
    echo "!! $*"
    exit 1
}

if [[ $# -lt 3 ]]; then
    echo "Usage: $0 \$1 \$2 \$3"
    echo "  \$1: tag(section name) for git configure in passwd.cnf"
    echo "  \$2: from branch"
    echo "  \$3: merge to branch"
    exit 1
fi


echo "-----------------------------"
echo "merge branch and push it to remote"
echo "-----------------------------"

git branch

echo "-----------------------------"
echo "current branch -> " $(git branch | sed -n '/\* /s///p')
echo "TODO:merge branch $3 from branch $2"
echo "-----------------------------"

git checkout $3
git merge --commit $2

echo "* push to remote *"
source $MYGIT_HOME/mygit-push $1

git branch
echo "* shell exec over,see you next time... *"
echo "-----------------------------"
git status
